import { Injectable } from '@angular/core';

import { Http } from '@angular/http';



@Injectable()
export class ServiceData {
  data: any;

  constructor(public http: Http) { }

  load(url, params) {
    if (this.data) {
      // already loaded data
      return Promise.resolve(this.data);
    }

    return new Promise(resolve => {
      this.http.get(url, params).subscribe(res => {
        this.data = res.json();
        resolve(this.data);
      });
    });
  }

}
